package bTree.LeetCode;

import java.util.ArrayList;
import java.util.List;

public class 二叉树的所有路径 {
    List<String> res = new ArrayList<>();

    public List<String> binaryTreePaths(TreeNode root) {
        String path = new String();
        loop(root, path);
        return res;

    }

    private void loop(TreeNode root, String path) {
        if(root==null){
            return;
        }
        if (root.left == null && root.right == null) {
            String p=path + "->" + root.val;
            res.add(p.substring(2));
        }
        String path2 = new String(path);
        if (path2!=null) {
            path2=path2+"->"+root.val;
        } else {
            path2 = path2 + root.val;
        }
        loop(root.left, path2);
        loop(root.right, path2);
    }
}